package com.ms.controller;

import com.ms.common.Result;
import com.ms.pojo.Resign_apply;
import com.ms.service.ResignApplyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resignApply")
@Tag(name = "离职办理接口接口")
public class ResignApplyController {
    @Autowired
    private ResignApplyService resignApplyService;

    /**
     * 查询所有离职申请
     */
    @GetMapping("/list")
    @Operation(summary = "查询所有离职申请")
    public Result<List<Resign_apply>> getAllResignApplies() {
        List<Resign_apply> resignApplies = resignApplyService.getAllResignApplies();
        return Result.success(resignApplies);
    }

    /**
     * 同意离职申请
     */
    @PutMapping("/agree/{resignId}")
    @Operation(summary = "同意离职申请")
    public Result<String> agreeResignApply(@PathVariable Integer resignId) {
        boolean success = resignApplyService.agreeResignApply(resignId);
        return success ? Result.success("已同意离职申请") : Result.error("同意操作失败");
    }

    /**
     * 拒绝离职申请
     */
    @PutMapping("/reject/{resignId}")
    @Operation(summary = "拒绝离职申请")
    public Result<String> rejectResignApply(@PathVariable Integer resignId) {
        boolean success = resignApplyService.rejectResignApply(resignId);
        return success ? Result.success("已拒绝离职申请") : Result.error("拒绝操作失败");
    }

}
